<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2019/7/27/027
 * Time: 8:57
 */

namespace app\common\service;


use rongyun\api\RongCloud;
use think\Db;

class ChatService
{
    private static  $instance;

    private static $ins;

    private function __construct()
    {
        self::$instance = self::getInstance();
    }




    public static function getInstance()
    {
        if (!self::$instance){
            self::$instance = new RongCloud(config('rongyun')['appKey'],config('rongyun')['appSecret']);
        }
        return self::$instance;
    }

    /**
     * 获取3.0版本对象
     * Created by xiaosong
     * E-mail:4155433@gmail.com
     */
    public static function getIns()
    {
        if (!self::$ins){
            self::$ins = new \RongCloud\RongCloud(config('rongyun')['appKey'],config('rongyun')['appSecret']);
        }
        return self::$ins;
    }


    public static function getOnlineCount(int $room_id) :int
    {
        $online = self::getInstance()->chatroom()->queryUser($room_id, '500', '2');
        $array  = json_decode($online,true);
        $total = 0;
        if ($array['code'] == 200) $total = $array['total'];
        return $total;
    }



}